package io.renren.modules.edu.controller;

import io.renren.common.utils.JacksonUtils;
import io.renren.common.utils.PageData;
import io.renren.common.utils.Result;
import io.renren.modules.edu.dto.TEduScientificDTO;
import io.renren.modules.edu.entity.TEduScientificEntity;
import io.renren.modules.edu.service.TEduScientificService;
import io.renren.modules.edu.vo.ScientificFileVO;
import io.renren.modules.edu.vo.TEduScientificVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 科研管理表
 *
 * @author zwp zwp
 * @since 1.0.0 2022-07-11
 */
@RestController
@RequestMapping("edu/teduscientific")
@Api(tags="科研管理表")
public class TEduScientificController {

    @Autowired
    private TEduScientificService tEduScientificService;

    @GetMapping("queryPageData")
    @ApiOperation("科研信息分页")
    public Result<PageData<TEduScientificVO>> queryPageData(@RequestParam Map<String, Object> params){
        PageData<TEduScientificVO> pageData = tEduScientificService.queryPageData(params);
        return new Result<PageData<TEduScientificVO>>().ok(pageData);
    }

    @GetMapping("queryScientificById/{id}")
    @ApiOperation("根据id获取科研信息")
    public Result<TEduScientificVO> queryScientificById(@PathVariable Long id){
        TEduScientificVO tEduScientificVO = tEduScientificService.queryScientificById(id);
        return new Result<TEduScientificVO>().ok(tEduScientificVO);
    }

    @PostMapping
    @ApiOperation("科研提交")
    public Result<Map<String, Object>> onSubmit(@RequestBody TEduScientificDTO dto){
        tEduScientificService.onSubmit(dto);
        return new Result<Map<String, Object>>();
    }

    @PutMapping
    @ApiOperation("科研信息更新")
    public Result<Map<String, Object>> update(@RequestBody TEduScientificDTO dto){
        tEduScientificService.getBaseMapper().updateById(JacksonUtils.obj2pojo(dto, TEduScientificEntity.class));
        return new Result<Map<String, Object>>();
    }

    @PostMapping("uploadFile")
    @ApiOperation("科研文件上传")
    public Result<ScientificFileVO> uploadPic(@RequestParam("file") MultipartFile uploadFile){
        ScientificFileVO scientificFileVO = tEduScientificService.uploadFile(uploadFile);
        return new Result<ScientificFileVO>().ok(scientificFileVO);
    }

    @DeleteMapping("{id}")
    @ApiOperation("科研信息删除")
    public Result<Map<String, Object>> delete(@PathVariable Long id){
        tEduScientificService.getBaseMapper().deleteById(id);
        return new Result<Map<String, Object>>();
    }

    @GetMapping("queryPageData/admin")
    @ApiOperation("科研信息分页(管理)")
    public Result<PageData<TEduScientificVO>> queryPageDataAdmin(@RequestParam Map<String, Object> params){
        PageData<TEduScientificVO> pageData = tEduScientificService.queryPageDataAdmin(params);
        return new Result<PageData<TEduScientificVO>>().ok(pageData);
    }

}
